package com.tjsinfo.tjsoa.worksummary.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.criterion.Expression;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.tjsinfo.tjsoa.worksummary.vo.WorkSummaryExamine;


/**
 * A data access object (DAO) providing persistence and search support for
 * WorkSummaryExamine entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.tjsinfo.tjsoa.worksummary.vo.WorkSummaryExamine
 * @author MyEclipse Persistence Tools
 */

public class WorkSummaryExamineDAO extends HibernateDaoSupport implements IWorkSummaryExamineDao {
	private static final Log log = LogFactory
			.getLog(WorkSummaryExamineDAO.class);

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#save(com.tjsinfo.tjsoa.worksummary.examine.WorkSummaryExamine)
	 */
	public void save(WorkSummaryExamine transientInstance) {
		log.debug("saving WorkSummaryExamine instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#delete(com.tjsinfo.tjsoa.worksummary.examine.WorkSummaryExamine)
	 */
	public void delete(WorkSummaryExamine persistentInstance) {
		log.debug("deleting WorkSummaryExamine instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#findById(java.lang.Integer)
	 */
	public WorkSummaryExamine findById(java.lang.Integer id) {
		log.debug("getting WorkSummaryExamine instance with id: " + id);
		try {
			WorkSummaryExamine instance = (WorkSummaryExamine) getHibernateTemplate()
					.get(
							"com.tjsinfo.tjsoa.worksummary.vo.WorkSummaryExamine",
							id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#findByExample(com.tjsinfo.tjsoa.worksummary.examine.WorkSummaryExamine)
	 */
	public List findByExample(WorkSummaryExamine instance) {
		log.debug("finding WorkSummaryExamine instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding WorkSummaryExamine instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from WorkSummaryExamine as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
    
	public List findByTwoProperty(String propertyName, Object value,String propertyName2, Object value2) {
		log.debug("finding WorkSummaryExamine instance with property: "
				+ propertyName + ", value: " + value);
		try {
			Criteria criteria = getSession().createCriteria(WorkSummaryExamine.class);
			criteria.add(Expression.eq(propertyName, value));
			criteria.add(Expression.eq(propertyName2, value2));
			return criteria.list();
			
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#findAll()
	 */
	public List findAll() {
		log.debug("finding all WorkSummaryExamine instances");
		try {
			String queryString = "from WorkSummaryExamine";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
 
	public WorkSummaryExamine findByUserId(java.lang.String userId) {
		log.debug("getting WorkSummaryExamine instance with user_id: " + userId);
		try {
			
			Object instance =  this.getHibernateTemplate().get(
					"com.tjsinfo.tjsoa.worksummary.examine.WorkSummaryExamine", userId);
			return (WorkSummaryExamine)instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#merge(com.tjsinfo.tjsoa.worksummary.examine.WorkSummaryExamine)
	 */
	public WorkSummaryExamine merge(WorkSummaryExamine detachedInstance) {
		log.debug("merging WorkSummaryExamine instance");
		try {
			WorkSummaryExamine result = (WorkSummaryExamine) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#attachDirty(com.tjsinfo.tjsoa.worksummary.examine.WorkSummaryExamine)
	 */
	public void attachDirty(WorkSummaryExamine instance) {
		log.debug("attaching dirty WorkSummaryExamine instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.tjsinfo.tjsoa.worksummary.examine.IWorkSummaryExamineDao#attachClean(com.tjsinfo.tjsoa.worksummary.examine.WorkSummaryExamine)
	 */
	public void attachClean(WorkSummaryExamine instance) {
		log.debug("attaching clean WorkSummaryExamine instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IWorkSummaryExamineDao getFromApplicationContext(
			ApplicationContext ctx) {
		return (IWorkSummaryExamineDao) ctx.getBean("WorkSummaryExamineDAO");
	}
}